#include<cstdio>
#include<cmath>

int main()
{
    int m,n,f1,f2,d1,d2,fs1,fs2;    
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        if(m>n)
            m^=n^=m^=n;
        f1=int(sqrt(float(m)));
        f2=int(sqrt(float(n)));
        if(f1*f1<m)
            f1++;
        if(f2*f2<n)
            f2++;
        d1=m-(f1-1)*(f1-1);
        d2=n-(f2-1)*(f2-1);
        fs1=d1;
        fs2=f2*2-1-(f1*2-1-d1);
        if(d2>=fs1&&d2<=fs2)
            printf("%d\n",(f2-f1)*2-(d1&1)+(d2&1));
        if(d2<fs1)
            printf("%d\n",(f2-f1)*2+fs1-d2);
        if(d2>fs2)
            printf("%d\n",(f2-f1)*2+d2-fs2);
    }
}
